home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 379 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.4 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: shankar@mti.mti.sgi.com (Shankar Unni)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Article for comp.std.c++: Eliminating #ifdef: if const
  5. Date: 19 Feb 1996 23:16:39 GMT
  6. Organization: Silicon Graphics, Inc., Mountain View, CA
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <4gb0a4$sa3@fido.asd.sgi.com>
  9. References: <199602160807.IAA06126@condor.ukc.ac.uk>
  10. Reply-To: shankar@engr.sgi.com
  11. NNTP-Posting-Host: taumet.eng.sun.com
  12. Content-Type: text
  13. X-Nntp-Posting-Host: boris.mti.sgi.com
  14. X-Newsreader: TIN [version 1.2 PL2]
  15. Content-Length: 1543
  16. X-Lines: 45
  17. Originator: clamage@taumet
  18.  
  19. Mark Russell (M.T.Russell@ukc.ac.uk) wrote:
  20.  
  21. > Here's an idea I had for a non-preprocessor replacement for #if and  #ifdef.
  22. >     if const (<expr>) { <stuff> }
  23.  
  24. > `if const' is a compile time version of `if'.  <expr> is a constant
  25. > expression which is convertible to bool.  If it yields true, <stuff>
  26. > is processed as normal.  Otherwise <stuff> is parsed into tokens, but
  27. > ignored except for counting { and } nesting.  <stuff> is anything that
  28. > can appear inside a namespace block.  `if const' does not introduce a
  29. > new scope.
  30.  
  31. No dice.
  32.  
  33. Often, an #ifdef covers just a small part of an expression that may be
  34. different between different environments, or some such small differences:
  35.  
  36.    if (some condition) {
  37. #ifdef SOMEIMPL
  38.     if (some other condition) {
  39. #endif /* SOMEIMPL */
  40.     /* code */
  41.     /* code */
  42.     /* code */
  43. #ifdef SOMEIMPL
  44.     }
  45. #endif /* SOMEIMPL */
  46.    }
  47.  
  48. Duplicating all the code so that each half is precisely correct in its {}
  49. matching is both tedious and error-prone (trying to verify that both parts
  50. of the expression are fixed).
  51.  
  52. Also, the #ifdefs serve a purpose in pointing out the fact that this piece
  53. of code is system-dependent.  The syntax you propose hides its warts rather
  54. too well, and make it easy for a reader to miss the significant piece of
  55. information that this area of code is system-dependent.
  56.  
  57. On the other hand, I'd really like to see function-like macros eased out
  58. of usage..
  59. --
  60. Shankar Unni                E-Mail:    shankar@sgi.com
  61. Silicon Graphics Inc.            Phone:    +1-415-933-2072
  62. URL:    http://reality.sgi.com/employees/shankar
  63.  
  64.  
  65. [ To submit articles: Try just posting with your newsreader.  If that fails,
  66.               use mailto:std-c++@ncar.ucar.edu
  67.   FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  68.   Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  69.   Comments? mailto:std-c++-request@ncar.ucar.edu
  70. ]
  71.